package com.mdx.zhizhao.controller;

import com.mdx.zhizhao.domain.*;
import com.mdx.zhizhao.service.DeliverService;
import com.mdx.zhizhao.service.EnterpriseService;
import com.mdx.zhizhao.service.JobService;
import com.mdx.zhizhao.service.SeekerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/deliver" ,produces = {MediaType.APPLICATION_JSON_VALUE,MediaType.APPLICATION_XML_VALUE})
@CrossOrigin(origins = "http://localhost:5173")
public class DeliverController {
    @Autowired
    private DeliverService deliverService;
    @Autowired
    private EnterpriseService enterpriseService;
    @Autowired
    private SeekerService seekerService;
    @Autowired
    private JobService jobService;
    @PostMapping("/updateDeliver")
    public Response<Deliver> updateDeliver(@RequestBody Deliver deliver){
        deliverService.upateDeliver(deliver);
        Response<Deliver> response=new Response<>();
        response.s(deliver,"成功");
        return response;
    }
    @PostMapping("/insertDeliver")
    public Response<Deliver> addDeliver(@RequestBody Deliver deliver){
        deliverService.insertDeliver(deliver);
        Response<Deliver> response=new Response<>();
        response.s(deliver,"成功");
        return response;
    }
    @PostMapping("/selectDeliverByEnterprise")
    public List<Deliver> selectDeliverByEnterprise(@RequestBody Deliver deliver){
        List<Deliver> delivers=deliverService.selectDeliverByEnterprise(deliver.getEnterpriseid());
        for(Deliver d:delivers){
            String s1=d.getEnterpriseid();
            String s2=d.getSeekerid();
            String s3=d.getJobid();
            Enterprise enterprise=enterpriseService.selectEnterprise(s1);
            Seeker seeker=seekerService.selectSeeker(s2);
            Job job=jobService.selectJob(s3);
            d.setJobname(job.getJobname());
            d.setEnterprisename(enterprise.getEnterprisename());
            d.setSeekername(seeker.getSeekername());
        }
        return delivers;
    }
    @PostMapping("/selectDeliverBySeeker")
    public List<Deliver> selectDeliverBySeeker(@RequestBody Deliver deliver){
        List<Deliver> delivers=deliverService.selectDeliverBySeeker(deliver.getSeekerid());
         for(Deliver d:delivers){
            String s1=d.getEnterpriseid();
            String s2=d.getSeekerid();
            String s3=d.getJobid();
            Enterprise enterprise=enterpriseService.selectEnterprise(s1);
            Seeker seeker=seekerService.selectSeeker(s2);
            Job job=jobService.selectJob(s3);
            d.setJobname(job.getJobname());
            d.setEnterprisename(enterprise.getEnterprisename());
            d.setSeekername(seeker.getSeekername());
        }
        return delivers;
    }

}
